package com.jiepu.daily.corejava.advanceed.part7network.day0812;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

/**
 * @Description:
 * @author: xinjie
 * @date: 2020/8/12  10:58
 */
public class ChartServer2 {
	public static void main(String[] args) {
		int port = 8888;
		try {
			ServerSocket ss = new ServerSocket(port);
			System.out.println("Server started. " + port);
			System.out.println("wait a Client ....");
			// 等待 接受client对象  Client 创建一个 Socket对象。
			Socket socket = ss.accept();
			System.out.println("一台client 已连接");

			// 接受Client的msg
			BufferedReader br = new BufferedReader(
					new InputStreamReader(socket.getInputStream()));
			System.out.println(br.readLine());

			// 向Client 发送msg
			PrintWriter pw = new PrintWriter(socket.getOutputStream(),true);
			System.out.println("Input Server say msg : ");
			Scanner scanner = new Scanner(System.in);
			pw.println(scanner.nextLine());


		} catch (IOException e) {
			e.printStackTrace();
		}
	} // main
}
